package ControlLayer;
import java.util.ArrayList;

import ModelLayer.*;
import DBLayer.*;

public class CtrEquipment {
	DBEquipment dbE;
	Equipment eq;
	
	CtrEquipment(){
		dbE = new DBEquipment();
		eq = new Equipment();
	}
	
	public ArrayList<Equipment> getAll(){
		return dbE.getAll();
		
	}
	
	public Equipment searchByName(String name){
		return dbE.find(name) ;
		
	}
	
	public Equipment searchByID(int id){
		return dbE.find_byID(id);
		
	}
	
	public int delete(int Prid){
		return dbE.delete(Prid);
	}
	
	public int updateEquipment(int Prid, String name, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, int currentStock, int minStock, int sid, String type, String description){
		Equipment equipment = new Equipment(Prid, name, purchasePrice, salesPrice, rentPrice, countryOfOrigin, currentStock, minStock, sid, type, description);
		return dbE.update(equipment);
	}
	
	public int insert(String name, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, int currentStock, int minStock, int sid, String type, String description){
		Equipment equipment = new Equipment(-1, name, purchasePrice, salesPrice, rentPrice, countryOfOrigin, currentStock, minStock, sid, type, description);
		int rc = -1;
		try{
			
			rc = dbE.insert(equipment);
			
		}catch(Exception e){
			System.out.println("Error with inserting a product");
		}
		return rc;
	}
	
	
}
